package com.szholly.pro.watergas_server.ps.android.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.szholly.pro.watergas_server.common.data.DataUtil;
import com.szholly.pro.watergas_server.ps.android.common.NonNullUtil;
import com.szholly.pro.watergas_server.ps.android.common.ValidUtils;
import com.szholly.data.general.GlobalParameter;
import com.szholly.data.general.RowBase;

public class IndustryWaterService {
	private static final String[] TASK_ARRAY = { "系统月巡检维护", "设备月校准", "设备月校验", "系统维修", "标准物质更换", "易耗品更换", "月盲样核查", "设备季度校验" };
	private static final String[] TASK_CODE_ARRAY = { "系统月巡检维护", "设备月校准", "设备月校验", "系统维修", "标准物质更换", "易耗品更换", "月盲样核查", "设备季度校验" };
	public static IndustryWaterService INSTANCE = new IndustryWaterService();

	public static IndustryWaterService getInstance() {
		return INSTANCE;
	}

	private IndustryWaterService(){
		mTaskServiceMap.put(TASK_CODE_ARRAY[0], new IndustryWaterTaskWeekCheck());
	}
	
	private Map<String, IndustryWaterTask>mTaskServiceMap= new HashMap<String, IndustryWaterTask>();

	public final IndustryWaterTask getTaskService(String taskTypeCode) throws Exception{
		IndustryWaterTask waterTask = mTaskServiceMap.get(taskTypeCode);
		ValidUtils.notNull(waterTask, "运维任务类型编号有误");
		return waterTask;
	}
	
	public final List<RowBase> getCompanyList() throws Exception {
		String sql = "select t.exp_no \"id\", max(t.name) \"name\", count(*) \"count\"\n"
				+ "  from BC_ENTERPRISE_ATTR t\n"
				+ "  left join BC_SITE_INFO t1\n"
				+ "    on t1.wwtp_id = t.exp_no\n"
				+ " where t1.station_category = '2'\n"
				+ " group by t.exp_no";
		return NonNullUtil.toList(DataUtil.getSelectRows(sql, null));
	}

	public final List<RowBase> getPointList(String companyCode) throws Exception {
		List<GlobalParameter> parms = new ArrayList<>();
		parms.add(new GlobalParameter("companyCode", companyCode));
		String sql = "select t.code \"id\", t.name \"name\", t.wwtp_id\n"
				+ "  from BC_SITE_INFO t\n"
				+ " where t.station_category = '2'\n"
				+ "   and t.wwtp_id = @companyCode";
		return NonNullUtil.toList(DataUtil.getSelectRows(sql, parms));
	}

	public final List<RowBase> getTaskList(String pointCode) throws Exception {
		List<RowBase> list = new ArrayList<>();
		for (int i = 0; i < TASK_ARRAY.length; i++) {
			RowBase rowBase = new RowBase();
			rowBase.put("id", TASK_CODE_ARRAY[i]);
			rowBase.put("name", TASK_ARRAY[i]);
			rowBase.put("count", i);
			list.add(rowBase);
		}
		return list;
	}
}
